﻿using System;
using System.Data;
using System.Collections.Generic;
using Maticsoft.Common;
using DBHelper.Model;
namespace DBHelper.BLL
{
	/// <summary>
	/// User
	/// </summary>
	public partial class User
	{
		private readonly DBHelper.DAL.User dal=new DBHelper.DAL.User();
		public User()
		{}
		#region  Method

		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int  Add(DBHelper.Model.User model)
		{
			return dal.Add(model);
		}

		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DBHelper.Model.User model)
		{
			return dal.Update(model);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int UserCode)
		{
			
			return dal.Delete(UserCode);
		}
		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool DeleteList(string UserCodelist )
		{
			return dal.DeleteList(UserCodelist );
		}

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DBHelper.Model.User GetModel(int UserCode)
		{
			
			return dal.GetModel(UserCode);
		}

		/// <summary>
		/// 得到一个对象实体，从缓存中
		/// </summary>
		public DBHelper.Model.User GetModelByCache(int UserCode)
		{
			
			string CacheKey = "UserModel-" + UserCode;
			object objModel = Maticsoft.Common.DataCache.GetCache(CacheKey);
			if (objModel == null)
			{
				try
				{
					objModel = dal.GetModel(UserCode);
					if (objModel != null)
					{
						int ModelCache = Maticsoft.Common.ConfigHelper.GetConfigInt("ModelCache");
						Maticsoft.Common.DataCache.SetCache(CacheKey, objModel, DateTime.Now.AddMinutes(ModelCache), TimeSpan.Zero);
					}
				}
				catch{}
			}
			return (DBHelper.Model.User)objModel;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			return dal.GetList(strWhere);
		}
		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			return dal.GetList(Top,strWhere,filedOrder);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DBHelper.Model.User> GetModelList(string strWhere)
		{
			DataSet ds = dal.GetList(strWhere);
			return DataTableToList(ds.Tables[0]);
		}
		/// <summary>
		/// 获得数据列表
		/// </summary>
		public List<DBHelper.Model.User> DataTableToList(DataTable dt)
		{
			List<DBHelper.Model.User> modelList = new List<DBHelper.Model.User>();
			int rowsCount = dt.Rows.Count;
			if (rowsCount > 0)
			{
				DBHelper.Model.User model;
				for (int n = 0; n < rowsCount; n++)
				{
					model = new DBHelper.Model.User();
					if(dt.Rows[n]["UserCode"]!=null && dt.Rows[n]["UserCode"].ToString()!="")
					{
						model.UserCode=int.Parse(dt.Rows[n]["UserCode"].ToString());
					}
					if(dt.Rows[n]["UserID"]!=null && dt.Rows[n]["UserID"].ToString()!="")
					{
					model.UserID=dt.Rows[n]["UserID"].ToString();
					}
					if(dt.Rows[n]["UserPassword"]!=null && dt.Rows[n]["UserPassword"].ToString()!="")
					{
					model.UserPassword=dt.Rows[n]["UserPassword"].ToString();
					}
					if(dt.Rows[n]["UserName"]!=null && dt.Rows[n]["UserName"].ToString()!="")
					{
					model.UserName=dt.Rows[n]["UserName"].ToString();
					}
					if(dt.Rows[n]["Sex"]!=null && dt.Rows[n]["Sex"].ToString()!="")
					{
					model.Sex=dt.Rows[n]["Sex"].ToString();
					}
					if(dt.Rows[n]["GraduateYear"]!=null && dt.Rows[n]["GraduateYear"].ToString()!="")
					{
						model.GraduateYear=int.Parse(dt.Rows[n]["GraduateYear"].ToString());
					}
					if(dt.Rows[n]["GraduateCollege"]!=null && dt.Rows[n]["GraduateCollege"].ToString()!="")
					{
					model.GraduateCollege=dt.Rows[n]["GraduateCollege"].ToString();
					}
					if(dt.Rows[n]["Major"]!=null && dt.Rows[n]["Major"].ToString()!="")
					{
						model.Major=dt.Rows[n]["Major"].ToString();
					}
					if(dt.Rows[n]["Education"]!=null && dt.Rows[n]["Education"].ToString()!="")
					{
						model.Education=int.Parse(dt.Rows[n]["Education"].ToString());
					}
					if(dt.Rows[n]["RegAddress"]!=null && dt.Rows[n]["RegAddress"].ToString()!="")
					{
					model.RegAddress=dt.Rows[n]["RegAddress"].ToString();
					}
					if(dt.Rows[n]["CurAddress"]!=null && dt.Rows[n]["CurAddress"].ToString()!="")
					{
					model.CurAddress=dt.Rows[n]["CurAddress"].ToString();
					}
					if(dt.Rows[n]["Mobile"]!=null && dt.Rows[n]["Mobile"].ToString()!="")
					{
						model.Mobile=decimal.Parse(dt.Rows[n]["Mobile"].ToString());
					}
					if(dt.Rows[n]["Tel"]!=null && dt.Rows[n]["Tel"].ToString()!="")
					{
						model.Tel=decimal.Parse(dt.Rows[n]["Tel"].ToString());
					}
					if(dt.Rows[n]["Email"]!=null && dt.Rows[n]["Email"].ToString()!="")
					{
					model.Email=dt.Rows[n]["Email"].ToString();
					}
					if(dt.Rows[n]["QQ"]!=null && dt.Rows[n]["QQ"].ToString()!="")
					{
					model.QQ=dt.Rows[n]["QQ"].ToString();
					}
					if(dt.Rows[n]["Isemployed"]!=null && dt.Rows[n]["Isemployed"].ToString()!="")
					{
						model.Isemployed=int.Parse(dt.Rows[n]["Isemployed"].ToString());
					}
					if(dt.Rows[n]["InCity"]!=null && dt.Rows[n]["InCity"].ToString()!="")
					{
						model.InCity=int.Parse(dt.Rows[n]["InCity"].ToString());
					}
					if(dt.Rows[n]["CompanyType"]!=null && dt.Rows[n]["CompanyType"].ToString()!="")
					{
						model.CompanyType=int.Parse(dt.Rows[n]["CompanyType"].ToString());
					}
					if(dt.Rows[n]["CurCompanyName"]!=null && dt.Rows[n]["CurCompanyName"].ToString()!="")
					{
					model.CurCompanyName=dt.Rows[n]["CurCompanyName"].ToString();
					}
					if(dt.Rows[n]["unEmployedReason"]!=null && dt.Rows[n]["unEmployedReason"].ToString()!="")
					{
					model.unEmployedReason=dt.Rows[n]["unEmployedReason"].ToString();
					}
					if(dt.Rows[n]["Mark"]!=null && dt.Rows[n]["Mark"].ToString()!="")
					{
					model.Mark=dt.Rows[n]["Mark"].ToString();
					}
					if(dt.Rows[n]["Status"]!=null && dt.Rows[n]["Status"].ToString()!="")
					{
					model.Status=dt.Rows[n]["Status"].ToString();
					}
					if(dt.Rows[n]["DocPath"]!=null && dt.Rows[n]["DocPath"].ToString()!="")
					{
					model.DocPath=dt.Rows[n]["DocPath"].ToString();
					}
					modelList.Add(model);
				}
			}
			return modelList;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetAllList()
		{
			return GetList("");
		}

		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			return dal.GetRecordCount(strWhere);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			return dal.GetListByPage( strWhere,  orderby,  startIndex,  endIndex);
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		//public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		//{
			//return dal.GetList(PageSize,PageIndex,strWhere);
		//}

		#endregion  Method
	}
}

